      module collocation
!     Functions to make RHS vector and System matrix entries
      use prec
      use bernstein
      contains

      double precision function rhs(x) 
!     Defines RHS vector
      implicit none

      real(dp), intent(in) :: x
      real(dp), parameter :: e = EXP(1.0_dp)

!      rhs = (4.-2.*x*x)*sin(x) + 4.*x*cos(x)
!      rhs = x**2./(e**x)
      rhs = 0.0_dp 

      end function rhs

      double precision function lhs(j,n,a,b,x) 
!     Evaluate value of differential operator applied to j-th basis function at position x
      implicit none

      integer, intent(in) :: j
      integer, intent(in) :: n
      real(dp), intent(in) :: x
      real(dp), intent(in) :: a,b

!     Problem 1.: LHS = y''(x) - y(x)
!      lhs = bernstein_basis_fun_derivative(2,j,n,a,b,x) - bernstein_basis_fun_eval(j,n,a,b,x)

!     Problem 2.: LHS = d2y/dx2+y
!      lhs = bernstein_basis_fun_derivative(2,j,n,a,b,x) + bernstein_basis_fun_eval(j,n,a,b,x) 

!    Problem 3.: LHS = dy/dx-y
      lhs = bernstein_basis_fun_derivative(1,j,n,a,b,x) - bernstein_basis_fun_eval(j,n,a,b,x) 
 

      end function lhs

      end module collocation
